<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let msgNum = 1 // 消息条数
    let cnt = 0 // 计数器
    const inerval = setInterval(() => {
      cnt = (cnt + 1) % 2
      if (msgNum === 0) {
        // 通过DOM修改title
        document.title += `聊天页面`
        clearInterval(interval)
        return
      }
      const prefix = cnt % 2 ? `新消息(${msgNum})` : ''
      document.title = `${prefix}聊天页面`
    }, 1000)
  </script>
</body>

</html>